local andu = fk.CreateSkill{
  name = "lingling__andu",
}

Fk:loadTranslationTable{
  ["lingling__andu"] = "暗度",
  [":lingling__andu"] = "出牌阶段限一次，你可以将【闪】当【过河拆桥】使用，然后若弃置了【闪】，则重置此技能。",

  ["#lingling__andu"] = "暗度：你可以将【闪】当【过河拆桥】使用",
}

andu:addEffect("viewas", {
  anim_type = "control",
  mute_card = false,
  prompt = "#lingling__andu",
  handly_pile = true,
  card_filter = function (self, player, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).trueName == "jink"
  end,
  view_as = function(self, player, cards)
    if #cards ~= 1 then return end
    local card = Fk:cloneCard("ling__dismantlement")
    card.skillName = andu.name
    card:addSubcards(cards)
    return card
  end,
  enabled_at_play = function (self, player)
    return player:usedSkillTimes(andu.name, Player.HistoryPhase) == 0
  end,
})

andu:addEffect(fk.AfterCardsMove, {
  can_refresh = function(self, event, target, player, data)
    local e = player.room.logic:getCurrentEvent():findParent(GameEvent.CardEffect)
    if e then
      local use = e.data
      if table.contains(use.card.skillNames, andu.name) then
        local yes = false
        for _, move in ipairs(data) do
          if move.proposer == player and move.moveReason == fk.ReasonDiscard and
            move.skillName == "ling__dismantlement_skill" then
            for _, info in ipairs(move.moveInfo) do
              if Fk:getCardById(info.cardId).trueName == "jink" then
                yes = true
              end
            end
          end
        end
        return yes
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    player:setSkillUseHistory(andu.name, 0, Player.HistoryPhase)
  end,
})

andu:addAI(nil, "vs_skill")

return andu
